/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mvc_template_app.dao;

import com.mvc_template_app.model.LoginForm;
import com.mvc_template_app.model.LoginForm;
import java.util.List;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author kirilarsov
 */
@Repository
@Transactional(readOnly = true)
public class LoginFormDaoImpl extends GenericDao implements LoginFormDao {

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public void saveLoginForm(LoginForm loginForm) {
        getHibernateTemplate().saveOrUpdate(loginForm);
    }

    @Transactional(readOnly = false)
    public void deleteLoginForm(LoginForm loginForm) {
        getHibernateTemplate().delete(loginForm);
    }

    public List<LoginForm> findByUsernameFromLoginForm(String username) {
        DetachedCriteria criteria = DetachedCriteria.forClass(LoginForm.class).
                add(Restrictions.eq("username", username));

        return (List<LoginForm>) getHibernateTemplate().findByCriteria(criteria);

    }
}
